﻿using System;
using System.Linq;
using Leap;

namespace LeapDemo001
{
	public class LeapListener : Listener
	{
		public void Log(string log)
		{
			Console.WriteLine(log);
		}

		public override void OnConnect(Controller controller)
		{
			Log("Connected");
		}

		public override void OnDisconnect(Controller controller)
		{
			Log("Disconnected");
		}

		public override void OnFrame(Controller controller)
		{
			Frame frame = controller.Frame();
			if (frame.Hands.Count == 0)
				return;

			var box = frame.InteractionBox;
			var point = frame.Pointables.Frontmost;

			Leap.Vector leapPoint = point.StabilizedTipPosition;
			var normilizedPos = box.NormalizePoint(leapPoint, false);

			var windowWidth = 800;
			var windowHeight = 600;

			var x = windowWidth*normilizedPos.x;
			var y = windowHeight*(1 - normilizedPos.y);

			Log(string.Format("x: {0}, y: {1}", x, y));
		}
	}
}